<template>
	<Form ref="loginForm" :model="form" :rules="rules">
		<FormItem label="选择教职工" prop="user_id" >
			<Select multiple  v-model="form.user_id"  style="width:80%" filterable>
				<Option v-for="(item,ind) in TeacherList" :value="item.user_id" :key="ind">
					{{ item.teacher_name ? item.teacher_name.zh : '' }}
				</Option>
			</Select>
		</FormItem>
		
		<FormItem style="width:100%">
			<Button type="primary" @click="SaveSubmit('loginForm')">添加</Button>
		</FormItem>
	</Form>
</template>

<script>
export default {
	name: 'DistributionOffice',
	layout: "menu",	
    props: ['condition'],
    data () {
		return {
			modal6: false,
			loading: true,
			title:'办公室分配教师',
			url: 'api/officearrange/v1/office_arrange_user/edit',
			TeacherList:[],
			buildings:[],
			form:{
				user_id: [],
			},
			rules: {
				user_id: [
					{ required: true, type: 'array', min:1, message: '请选择教师', trigger: 'change' }
				],
			}
		}
    },
    methods: {
		teacher () {
			let that = this
            that.$http.get('api/systemctl/orgDepartments/getDepartmentTeacher/' + that.condition.depart_id).then(val=>{
				console.log(val, 'depart data')
				that.TeacherList = val.data
            }).catch(err=>{
            })
		},

		SaveSubmit(name) {
			this.$refs[name].validate((valid) => {
				if (valid) {
					this.addData ()
				} else {
					this.$Message.error('验证失败!');
				}
			})
		},

		addData () {
			let that = this
			let data = {
				user_id: that.form.user_id,
				room_id: that.condition.room_id
			}
            that.$http.post('api/teacher/officeArrangeUser/save', data).then(val=>{
				this.$emit('requery',true)
            }).catch(err=>{
            })
		},

		editData () {
			let that = this
			let data = {
				user_id: that.form.user_id,
				room_id: that.condition.room_id,
				id: that.condition.data_id
			}
            that.$http.get('api/teacher/officeArrangeUser/update' + data).then(val=>{
				console.log(val, 'depart data')
				this.$emit('requery',true)
            }).catch(err=>{
            })
		},

		getFormData () {
			let that = this
            that.$http.get('api/teacher/officeArrange/getById/' + that.condition.data_id).then(val=>{
				console.log(val, 'get form data')
            }).catch(err=>{
            })
		}
	},
	
	mounted () {
		this.teacher ()
		// if (this.condition.data_id) this.getFormData ()
	}
}
</script>
